#! /bin/sh
imageUrl=registry.cn-shanghai.aliyuncs.com/jokerak/ai-back
echo "镜像网址---$imageUrl"
containerId=$(docker ps -a | grep -w ${imageUrl} | awk '{print $1}')
if [ "$containerId" != "" ]; then
  #停掉容器
  docker stop $containerId
  #删除容器
  docker rm $containerId
  echo "成功删除容器"
fi
#查询镜像是否存在，存在则删除
imageId=$(docker images | grep -w ${imageUrl} | awk '{print $3}')
if [ "$imageId" != "" ]; then
  #删除镜像
  docker rmi -f $imageId
  echo "成功删除镜像"
fi
# 登录Harbor私服
docker login --username=fakerlove7 -p 1654697013wan registry.cn-shanghai.aliyuncs.com
# 下载镜像
docker pull ${imageUrl}
# 启动容器
docker run -di -p 18001:8080 --name ai_back ${imageUrl}
echo "容器启动成功"
